﻿using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GuanYijia.Application.ProductionManagement
{
    public class RabbitMQHelperNew
    {
        private static ConnectionFactory factory;
        private static object lockObj = new object();

        /// <summary>
        /// 获取单个RabbitMQ连接
        /// </summary>
        /// <returns></returns>
        public static async Task<IConnection> GetConnectionAsync()
        {
            if (factory == null)
            {
                lock (lockObj)
                {
                    if (factory == null)
                    {
                        factory = new ConnectionFactory
                        {
                            HostName = "47.94.104.5", // IP
                            Port = 5672, // 端口
                            UserName = "admin", // 账号
                            Password = "admin", // 密码
                            VirtualHost = "develop" // 虚拟主机
                        };
                    }
                }
            }
            // 异步创建连接并返回
            return await factory.CreateConnectionAsync();
        }
    }
}
